<!-- Begin: cppage - Ads -->
<?
if ($_GET['category'] == 'produtos') {
    $category = 'P';
    $name = 'produtos';
} else if ($_GET['category'] == 'veiculos') {
    $category = 'V';
    $name = 'veículos';
}
?>
<div class="cppage ads">
    <?
    if (((CPanel::$account->a_type == 'F')) or ((CPanel::$account->e_id_plan <> NULL or CPanel::$account->e_id_product_plan <> NULL ) and (CPanel::$account->a_type == 'J')) and isset($category)) {
        ?>
        <div class="header">
            <h2>Gerenciar anúncios de <?= ucfirst($name); ?></h2>
        </div>
        <?
        if ($category == 'V') {
            if (CPanel::$exceeded_ad) {
                ?>
                <div class="alert-msg exceededad">Caro usuário, o limite de cadastro de anúncio do plano escolhido foi atingido!</div>
            <? } ?>

            <div class="table">
                <div class="thead">
                    <ul>
                        <li style="width: <?= (CPanel::$account->a_type == 'F') ? '55' : '40' ?>px"></li>
                        <li style="width: 75px">Criado em</li>
                        <li>Modelo</li>
                        <li style="width: 70px">Ano/Mod.</li>
                        <li style="width: 70px">Placa</li>
                        <li style="width: 70px">Cor</li>
                        <li style="width: 150px">Versão</li>
                        <li>Valor</li>
                        <? if(CPanel::$account->a_type == 'F'){ ?>
                        <li style="width: 120px">Situação</li>
                        <? } ?>
                    </ul>
                </div>
                <? if (CPanel::$vehicles_ads == null) { ?>
                    <div class="empty odd">Nenhum registro foi encontrado</div>
                <? } else { ?>
                    <div class="tbody">
                        <? foreach (CPanel::$vehicles_ads as $key => $vehicles_ad) { ?>
                            <ul<?= (($key + 1) % 2 != 0) ? ' class="odd"' : '' ?>>
                                <li>
                                    <a href="<?= __BASE_URI__ ?>painel/remover-anuncio/<?= $vehicles_ad->id ?>" class="remove-ads" title="Remover"></a>
                                    <a href="<?= __BASE_URI__ ?>painel/alterar-anuncio/<?= $vehicles_ad->id ?>" class="edit-ads" title="Alterar"></a>
                                </li>
                                <li><?= date('d/m/Y', strtotime($vehicles_ad->dateinclusion)) ?></li>
                                <li><?= $vehicles_ad->m_name ?></li>
                                <li><?= $vehicles_ad->firstreg . '/' . $vehicles_ad->modelyear ?></li>
                                <li><?=  strtoupper($vehicles_ad->plate)?></li>
                                <li><?= $vehicles_ad->color?></li>
                                <li><? if(!isset($vehicles_ad->version)){ echo " '' "; }else{ echo $vehicles_ad->version; }?></li>
                                <li style="text-align: right;">R$ <?= Util::format_money($vehicles_ad->v_price - $vehicles_ad->discount) ?></li>
                                <? if(CPanel::$account->a_type == 'F'){ ?>
                                <li>
                                    <?
                                    switch ($vehicles_ad->s_id) {
                                        case 1:
                                            $status = 'payment';
                                            break;
                                        case 2:
                                            $status = 'sold';
                                            break;
                                        case 3:
                                            if (CPanel::$account->a_type == 'J' && CPanel::$account->id_status == 4) {
                                                $status = 'disabled';
                                                $vehicles_ad->s_name = 'Desativado';
                                            } else {
                                                if (CPanel::$account->a_type == 'F')
                                                    $secamount = $vehicles_ad->daysamount * 24 * 60 * 60;
                                                else
                                                    $secamount = CPanel::$account->daysamount * 24 * 60 * 60;
                                                $expiration = strtotime($vehicles_ad->paydate) + $secamount;
                                                if ($expiration > time())
                                                    $status = 'activated'; else {
                                                    $status = 'disabled';
                                                    if (CPanel::$account->a_type == 'F')
                                                        $vehicles_ad->s_name = 'Vencido';
                                                    else
                                                        $vehicles_ad->s_name = 'Desativado';
                                                }
                                            }
                                            break;
                                        default:
                                            $status = 'disabled';
                                            break;
                                    }
                                    ?>
                                    <span class="<?= $status ?>"><?= $vehicles_ad->s_name ?></span>
                                </li>
                                <? } ?>
                            </ul>
                        <? } ?>
                    </div>
                </div>
            <? } ?>
        <? }else if ($category == 'P') { ?>
            <div class="table">
                <div class="thead">
                    <ul>
                        <li style="width: <?= (CPanel::$account->a_type == 'F') ? '25' : '25' ?>px"></li>
                        <li style="width: 20px">Criado em</li>
                        <li style="width: 400px">Nome</li>
                        <li style="width: 50px">Valor</li>
                    </ul>
                </div>
                <? if (CPanel::$products_ads == null) { ?>
                    <div class="empty odd">Nenhum registro foi encontrado</div>
                <? } else { ?>
                    <div class="tbody">
                        <? foreach (CPanel::$products_ads as $key => $products_ads) {
                            ?>
                            <ul<?= (($key + 1) % 2 != 0) ? ' class="odd"' : '' ?>>
                                <li>
                                    <a href="javascript:;" class="remove-ads product" rel="<?= $products_ads->id ?>" title="Remover"></a>
                                    <a href="<?= __BASE_URI__ ?>painel/alterar-produto/<?= $products_ads->id ?>" class="edit-ads" title="Alterar"></a>
                                    <? if (CPanel::$account->a_type == 'F' && $vehicles_ad->s_id == 1) { ?>
                                        <a href="javascript:;" class="pay-ads" title="Efetuar pagamento" data="<?= $products_ads->p_id ?>"></a>
                                    <? } ?>
                                </li>
                                <li><?= date('d/m/Y', strtotime($products_ads->p_dateinclusion)) ?></li>
                                <li><?= $products_ads->p_name ?></li>
                                <li>R$ <?= Util::format_money($products_ads->p_price) ?></li>
                            </ul>
                        <? } ?>
                    </div>
                <? } ?>
            </div>
            <?
        }
    } else {
        ?>
        <div class="header">
            <h2>Inicial</h2>
        </div>
        <div class="last-transactions">
        </div>            
        <div class="last-transactions">
        </div>            
    <? } ?>
</div> <!-- End -->